//
//  ReviewCell.m
//  cityStar
//
//  Created by joyban on 15-1-28.
//  Copyright (c) 2015年 tiny. All rights reserved.
//

#import "ReviewCell.h"
#import "NSDate+Helper.h"

@implementation ReviewCell

+(CGFloat)heightOfTableCell
{
    return 44;
}

-(void)configWithMessage:(ReViewListMessage *)message
{
    self.labeltitle.text = [NSString stringWithFormat:@"%@",message.creator_name];
    self.labelreView.text = [NSString stringWithFormat:@"%@",message.comment];
//NSData da
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[[NSString stringWithFormat:@"%@",message.create_time] intValue]];
//    NSTimeInterval time = -[confromTimesp timeIntervalSinceNow];
    
    self.labeltimes.text = [self dateStringFromNow:confromTimesp];
    
//    self.labeltimes.text = [NSString stringWithFormat:@"%@",[NSDate dateFromString:[NSString stringWithFormat:@"%@",message.create_time] withFormat:@""]];
}

-(NSString*)dateStringFromNow:(NSDate*)date{
    NSTimeInterval time = -[date timeIntervalSinceNow];
    if (time<0) {
        return @"";
    }else {
        if (time<3600*24) {
            if (time>=0.0 && time <60.0) {
                return @"刚刚";
            }else if (time>=60.0 && time <60.0*60.0) {
                return [NSString stringWithFormat:@"%d分钟前",(int)time/60];
            }else if (time>=3600.0 && time <3600.0*24) {
                return [NSString stringWithFormat:@"%d小时前",(int)time/3600];;
            }
        }else {
            
            NSCalendar* calendar = [NSCalendar currentCalendar];
            NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit|NSWeekCalendarUnit fromDate:date toDate:[NSDate date] options:0];
            if ([components year]>0) {
                int month = [components year]*12+[components month];
                return [NSString stringWithFormat:@"%d月前",month];
            }else if([components month]>0){
                int month = [components month];
                return [NSString stringWithFormat:@"%d月前",month];
            }else if([components week]>0){
                return [NSString stringWithFormat:@"%d周前",[components week]];
            }else if([components day]>0){
                return [NSString stringWithFormat:@"%d天前", [components day]];
            }
        }
    }
    return @"";
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
